#ifndef _FIFO_H_
#define _FIFO_H_

#include <salof_config.h>

#define			FIFO_READ		0
#define			FIFO_WRITE		1

#define 		FIFO_MAX(a,b) (((a) > (b)) ? (a) : (b))
#define 		FIFO_MIN(a,b) (((a) < (b)) ? (a) : (b))

// #define	FIFO_MAX(x,y) 	({		\
// 	const typeof(x) _x	= (x);	\
// 	const typeof(y) _y	= (y);	\
// 	(void) (&_x == &_y)	;		\
// 	_x > _y ? _x : _y;	})

// #define	FIFO_MIN(x,y) 	({		\
// 	const typeof(x) _x	= (x);	\
// 	const typeof(y) _y	= (y);	\
// 	(void) (&_x == &_y)	;		\
// 	_x < _y ? _x : _y;	})

struct fifo
{
	unsigned int    size;       /* fifo size */
	unsigned int    in;         /* Data input pointer (in % size) */
	unsigned int    out;        /* Data output pointer (out % size) */
	salof_mutex     mutex[2];   /* Mutex */       
	void            *buff;    /* data area */
};
typedef struct fifo * fifo_t;

fifo_t fifo_create(unsigned int size);
unsigned int fifo_write(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
unsigned int fifo_read(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
unsigned int fifo_read_able(fifo_t fifo);
unsigned int fifo_write_able(fifo_t fifo);

#endif // !_FIFO_H_

